package com.wc.codeforces.思维.Gorilla_and_the_Exam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/1/4 22:47
 * @description
 * https://codeforces.com/contest/2057/problem/B
 */
public class Main {
    /**
     * 题意：选定 l, r 删除其中的最小值
     * 思路：
     * 也就是统计里面最少可以有多少种不同数字, 多转换为同一种数字就好了, 将最少的转换为同样类型的数据
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static PriorityQueue<Integer> q = new PriorityQueue<>();
    static int n, m;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            Arrays.sort(a, 1, n + 1);
            int v = a[1], num = 0;
            for (int i = 1; i <= n; i++) {
                if (a[i] == v) num++;
                else {
                    q.add(num);
                    v = a[i];
                    num = 1;
                }
            }
            q.add(num);
            int res = 0;
            while (!q.isEmpty()) {
                int t = q.poll();
                if (m >= t) m -= t;
                else res++;
            }
            // 全部都能转化
            if (res == 0) res = 1;
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

